package com.tencent.sr.iris.basic.saas.dependency;

import com.tencent.sr.iris.goods.core.interfaces.client.ActivityClient;
import com.tencent.sr.iris.goods.core.interfaces.request.activity.ActivityRequest;
import com.tencent.sr.iris.goods.core.interfaces.request.activity.ListActivityResponse;
import com.tencent.sr.rmall.common.primitive.HttpResult;
import com.tencent.sr.rmall.springbootstarter.authtoken.localbean.AppUser;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

@Slf4j
@Component
public class GoodsDependency {
    @Resource
    private ActivityClient activityClient;
    @Resource
    private AppUser appUser;

    public String getActivityWxAppPath(String activityId) {
        ActivityRequest activityRequest = new ActivityRequest();
        activityRequest.setRootSaasId(appUser.getSaasId());
        List<String> activityIds = new ArrayList<>();
        activityIds.add(activityId);
        activityRequest.setActivityIdList(activityIds);
        HttpResult<List<ListActivityResponse>> listHttpResult = activityClient.listActivity(activityRequest);
        if (listHttpResult.isSuccess() && !CollectionUtils.isEmpty(listHttpResult.getData())) {
            ListActivityResponse activityResponse = listHttpResult.getData().get(0);
            return activityResponse.getWxAppPath();
        }
        return "";
    }
}
